<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: pink;
        }
    </style>
</head>

<body>

    <div></div>

    <script>
        //1.获取元素
        var div = document.querySelector('div')
        //2.绑定事件  处理程序
        var flag = 0;
        div.onclick = function () {
            if (flag == 0) {
                this.style.backgroundColor = 'red'
                this.style.width = '200px'
                flag = 1;
            }
            else {
                this.style.backgroundColor = 'pink'
                flag = 0;
            }

        }
    </script>
</body>

</html>